<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info">
            <view class="u_title">
              {{ user.nickName }}
            </view>
			<view class="u_title">
              账号：{{ name }}
            </view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <view class="iconfont icon-right"></view>
        </view>
      </view>
    </view>

    <view class="content-section">

      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view>账号与安全</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleStorage">
          <view class="menu-item-box">
            <view>清除缓存</view>
          </view>
        </view>
		<view class="list-cell list-cell-arrow" @click="handleDataSyn">
		  <view class="menu-item-box">
		    <view>数据同步</view>
		  </view>
		</view>
		<view class="list-cell list-cell-arrow" @click="handleUpdate">
		  <view class="menu-item-box">
		    <view>系统自检</view>
		  </view>
		</view>
      </view>
	  <view style="padding: 15px;">
		  <button size="default" style="background-color: #255CC3;color: #ffffff;" @click="handleLogout">退出登录</button>
	  </view>
    </view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
  import {toast} from '@/utils/common'
  import config from '@/config.js'
  import { getUserProfile } from "@/api/system/user"
  import { checkAppUpdate } from '@/utils/appUpdate.js'
  import {getNimToken,getRefreshToken} from '@/api/nim/nim'
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
		avatar: this.$store.getters.avatar,
        version: getApp().globalData.config.appInfo.version,
		user:{}
      }
    },
    computed: {
		windowHeight() {
			return uni.getSystemInfoSync().windowHeight - 50
		}
    },
	onLoad() {
		this.getUser()
		console.log(this.$store.state.user.userInfo.id);
	},
	onShow(){
		this.avatar = this.$store.getters.avatar;
		this.getUser()
		console.log(this.$store.getters.avatar);
	},
    methods: {
	  getUser() {
		getUserProfile().then(response => {
		  this.user = response.data.user
		  console.log(this.user);
		  // getRefreshToken(this.user.id).then(res=>{
			 //  console.log(res)
		  // });
		})
	  },
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToEditInfo() {
        this.$tab.navigateTo('/pages/mine/info/edit')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/pages/index')
          })
        })
      },
      handleHelp() {
        this.$tab.navigateTo('/pages/mine/help/index')
      },
	  handleStorage(){
		  toast("清除成功");
	  },
	  handleDataSyn(){
		  toast("同步成功");
	  },
	  handleUpdate(){
		  checkAppUpdate(true)
	  }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 45px 15px 45px 15px;
	  border-bottom-left-radius: 25px;
	  border-bottom-right-radius: 25px;
      background-color: #255CC3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

	  .menu-list{
		  border-radius: 20px;
		  .list-cell{
			  padding: 17px 15px;
		  }
		  
		  .list-cell:first-child {
		      border-radius: 10px 10px 0 0;
		  }
		  
		  .menu-item-box {
		    font-family: Source Han Sans CN;
		    font-size: 16px;
		    font-weight: normal;
		    line-height: 16px;
		    letter-spacing: 0em;
		    
		    color: #1F1E1E;
		  }
	  }
    
    }
  }
</style>
